from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-09 14:02:35.706129
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 09, Apr, 2022
Time: 14:02:41
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.8913
Nobs: 621.000 HQIC: -49.2839
Log likelihood: 7539.71 FPE: 3.07523e-22
AIC: -49.5335 Det(Omega_mle): 2.66341e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.337108 0.064053 5.263 0.000
L1.Burgenland 0.105895 0.039990 2.648 0.008
L1.Kärnten -0.110561 0.020928 -5.283 0.000
L1.Niederösterreich 0.195719 0.083590 2.341 0.019
L1.Oberösterreich 0.118072 0.082326 1.434 0.152
L1.Salzburg 0.259438 0.042418 6.116 0.000
L1.Steiermark 0.042074 0.055870 0.753 0.451
L1.Tirol 0.104467 0.045163 2.313 0.021
L1.Vorarlberg -0.065683 0.039884 -1.647 0.100
L1.Wien 0.020078 0.073292 0.274 0.784
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.047077 0.137295 0.343 0.732
L1.Burgenland -0.038103 0.085717 -0.445 0.657
L1.Kärnten 0.042043 0.044859 0.937 0.349
L1.Niederösterreich -0.200873 0.179171 -1.121 0.262
L1.Oberösterreich 0.455768 0.176462 2.583 0.010
L1.Salzburg 0.282827 0.090920 3.111 0.002
L1.Steiermark 0.113325 0.119754 0.946 0.344
L1.Tirol 0.306196 0.096804 3.163 0.002
L1.Vorarlberg 0.026566 0.085489 0.311 0.756
L1.Wien -0.026293 0.157098 -0.167 0.867
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191096 0.032740 5.837 0.000
L1.Burgenland 0.088733 0.020440 4.341 0.000
L1.Kärnten -0.007210 0.010697 -0.674 0.500
L1.Niederösterreich 0.244318 0.042726 5.718 0.000
L1.Oberösterreich 0.160654 0.042080 3.818 0.000
L1.Salzburg 0.040230 0.021681 1.856 0.064
L1.Steiermark 0.028745 0.028557 1.007 0.314
L1.Tirol 0.082898 0.023084 3.591 0.000
L1.Vorarlberg 0.054551 0.020386 2.676 0.007
L1.Wien 0.117691 0.037462 3.142 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111374 0.032778 3.398 0.001
L1.Burgenland 0.042379 0.020464 2.071 0.038
L1.Kärnten -0.013122 0.010710 -1.225 0.220
L1.Niederösterreich 0.174462 0.042775 4.079 0.000
L1.Oberösterreich 0.333974 0.042129 7.927 0.000
L1.Salzburg 0.100347 0.021706 4.623 0.000
L1.Steiermark 0.113858 0.028590 3.982 0.000
L1.Tirol 0.091191 0.023111 3.946 0.000
L1.Vorarlberg 0.060770 0.020410 2.977 0.003
L1.Wien -0.015816 0.037506 -0.422 0.673
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114047 0.061364 1.859 0.063
L1.Burgenland -0.045793 0.038311 -1.195 0.232
L1.Kärnten -0.045428 0.020049 -2.266 0.023
L1.Niederösterreich 0.139422 0.080080 1.741 0.082
L1.Oberösterreich 0.162091 0.078869 2.055 0.040
L1.Salzburg 0.284882 0.040637 7.010 0.000
L1.Steiermark 0.060987 0.053524 1.139 0.255
L1.Tirol 0.159439 0.043266 3.685 0.000
L1.Vorarlberg 0.098105 0.038209 2.568 0.010
L1.Wien 0.074666 0.070215 1.063 0.288
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056332 0.048033 1.173 0.241
L1.Burgenland 0.025544 0.029988 0.852 0.394
L1.Kärnten 0.053096 0.015694 3.383 0.001
L1.Niederösterreich 0.194513 0.062683 3.103 0.002
L1.Oberösterreich 0.332428 0.061735 5.385 0.000
L1.Salzburg 0.036087 0.031808 1.135 0.257
L1.Steiermark 0.013446 0.041896 0.321 0.748
L1.Tirol 0.120844 0.033867 3.568 0.000
L1.Vorarlberg 0.067212 0.029908 2.247 0.025
L1.Wien 0.101445 0.054961 1.846 0.065
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168531 0.057787 2.916 0.004
L1.Burgenland 0.005306 0.036078 0.147 0.883
L1.Kärnten -0.065773 0.018881 -3.484 0.000
L1.Niederösterreich -0.104053 0.075413 -1.380 0.168
L1.Oberösterreich 0.207354 0.074272 2.792 0.005
L1.Salzburg 0.054449 0.038268 1.423 0.155
L1.Steiermark 0.247415 0.050404 4.909 0.000
L1.Tirol 0.501804 0.040744 12.316 0.000
L1.Vorarlberg 0.063512 0.035982 1.765 0.078
L1.Wien -0.076039 0.066122 -1.150 0.250
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153569 0.064087 2.396 0.017
L1.Burgenland -0.002453 0.040011 -0.061 0.951
L1.Kärnten 0.062559 0.020939 2.988 0.003
L1.Niederösterreich 0.170052 0.083634 2.033 0.042
L1.Oberösterreich -0.055396 0.082369 -0.673 0.501
L1.Salzburg 0.207772 0.042440 4.896 0.000
L1.Steiermark 0.139477 0.055899 2.495 0.013
L1.Tirol 0.058073 0.045186 1.285 0.199
L1.Vorarlberg 0.146888 0.039905 3.681 0.000
L1.Wien 0.122126 0.073331 1.665 0.096
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.382396 0.037757 10.128 0.000
L1.Burgenland -0.003733 0.023573 -0.158 0.874
L1.Kärnten -0.020825 0.012336 -1.688 0.091
L1.Niederösterreich 0.203653 0.049273 4.133 0.000
L1.Oberösterreich 0.230328 0.048528 4.746 0.000
L1.Salzburg 0.036806 0.025004 1.472 0.141
L1.Steiermark -0.012273 0.032933 -0.373 0.709
L1.Tirol 0.089585 0.026622 3.365 0.001
L1.Vorarlberg 0.052679 0.023510 2.241 0.025
L1.Wien 0.044010 0.043203 1.019 0.308
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036932 0.110181 0.173452 0.139505 0.102849 0.081590 0.036167 0.211607
Kärnten 0.036932 1.000000 -0.025688 0.131016 0.049535 0.085578 0.443602 -0.066074 0.089693
Niederösterreich 0.110181 -0.025688 1.000000 0.315202 0.122530 0.276452 0.068951 0.155071 0.293916
Oberösterreich 0.173452 0.131016 0.315202 1.000000 0.214492 0.298153 0.166790 0.138654 0.240700
Salzburg 0.139505 0.049535 0.122530 0.214492 1.000000 0.126414 0.093701 0.106338 0.126133
Steiermark 0.102849 0.085578 0.276452 0.298153 0.126414 1.000000 0.135890 0.110877 0.039181
Tirol 0.081590 0.443602 0.068951 0.166790 0.093701 0.135890 1.000000 0.065811 0.150267
Vorarlberg 0.036167 -0.066074 0.155071 0.138654 0.106338 0.110877 0.065811 1.000000 -0.003527
Wien 0.211607 0.089693 0.293916 0.240700 0.126133 0.039181 0.150267 -0.003527 1.000000